<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>C&#43;&#43;右值语义的基石——完美转发 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="C&#43;&#43;右值语义的基石——完美转发"><meta property="og:title" content="C&#43;&#43;右值语义的基石——完美转发" />
<meta property="og:description" content="C&#43;&#43;右值语义的基石——完美转发" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-02-04T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-02-04T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="C&#43;&#43;右值语义的基石——完美转发"/>
<meta name="twitter:description" content="C&#43;&#43;右值语义的基石——完美转发"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" /><link rel="prev" href="https://acking-you.github.io/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98%E5%92%8C%E4%B8%BAk%E7%9A%84%E6%9C%80%E5%B0%91%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%AD%97%E6%95%B0%E7%9B%AE/" /><link rel="next" href="https://acking-you.github.io/posts/c&#43;&#43;%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%AE%9E%E7%8E%B0%E5%AD%A6%E7%94%9F%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "C++右值语义的基石——完美转发",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/c\u002b\u002b%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91\/"
        },"genre": "posts","keywords": "C\u002b\u002b右值语义的基石——完美转发","wordcount":  1085 ,
        "url": "https:\/\/acking-you.github.io\/posts\/c\u002b\u002b%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91\/","datePublished": "2022-02-04T00:00:00+00:00","dateModified": "2022-02-04T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "C++右值语义的基石——完美转发"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png, https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png 1.5x, https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png"
        title="C&#43;&#43;右值语义的基石——完美转发" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">C&#43;&#43;右值语义的基石——完美转发</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/%E7%8E%B0%E4%BB%A3c++%E8%AF%AD%E6%B3%95/"><i class="far fa-folder fa-fw"></i>现代C++语法</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-02-04">2022-02-04</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1085 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 3 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#什么是完美转发">什么是完美转发？</a></li>
    <li><a href="#如何实现完美转发">如何实现完美转发？</a></li>
    <li><a href="#任何模板库都离不开完美转发">任何模板库都离不开完美转发</a></li>
    <li><a href="#stdforward的实现原理">std::forward的实现原理</a></li>
    <li><a href="#收获">收获</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="什么是完美转发">什么是完美转发？</h2>
<p>熟悉现代C++语法的都应该清楚，C++把变量分为左值和右值，为了实现对资源的转移而不是拷贝，右值和对应的移动构造函数应运而生，但我们发现，很多时候我们并不能把左值和右值精确的传递给对应版本的函数进行处理，比如下面一个简单的代码，你会发现<strong>即使我们把函数的参数类型设置为右值引用，但当拿它去调用对应的构造函数时，它给出的竟然是拷贝构造</strong>！故这个转发还不够完美！</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span><span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp"></span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">test</span><span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">test</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
    <span class="n">test</span><span class="p">(</span><span class="n">test</span><span class="o">&amp;&amp;</span> <span class="n">p</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;move construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">test</span><span class="p">(</span><span class="k">const</span> <span class="n">test</span><span class="o">&amp;</span> <span class="n">p</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;copy construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>
<span class="kt">void</span> <span class="nf">test_fun</span><span class="p">(</span><span class="n">test</span><span class="o">&amp;&amp;</span> <span class="n">p</span><span class="p">){</span>
    <span class="n">test</span> <span class="n">q</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
    <span class="k">return</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">test_fun</span><span class="p">(</span><span class="n">test</span><span class="p">());</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><blockquote>
<p>为什么会出现这种情况呢？</p>
<p>因为<strong>无论传入的形参是左值还是右值，对于函数内部来说，形参既有名称又能寻址，因此它都被认为是左值</strong>。</p>
</blockquote>
<h2 id="如何实现完美转发">如何实现完美转发？</h2>
<p>实现完美转发很简单，我们在现代C++中只需要 <code>forward&lt;T&gt;</code> 这个模板函数即可完成，其实际原理就是利用的 C++11 模板中提供的折叠引用的语法，最终达到的效果就是，把参数的类型强制转换为它该有的类型，是左值就转为左值，是右值就转为右值，从而实现该调用哪个版本的函数就调用哪个版本的函数，不再只被认定为右值了！</p>
<blockquote>
<p>先前的代码可以如此实现完美转发：</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span><span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp"></span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">test</span><span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">test</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
    <span class="n">test</span><span class="p">(</span><span class="n">test</span><span class="o">&amp;&amp;</span> <span class="n">p</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;move construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">test</span><span class="p">(</span><span class="k">const</span> <span class="n">test</span><span class="o">&amp;</span> <span class="n">p</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;copy construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>
<span class="kt">void</span> <span class="nf">test_fun</span><span class="p">(</span><span class="n">test</span><span class="o">&amp;&amp;</span> <span class="n">p</span><span class="p">){</span>
    <span class="n">test</span> <span class="n">q</span><span class="p">(</span><span class="n">forward</span><span class="o">&lt;</span><span class="n">test</span><span class="o">&gt;</span><span class="p">(</span><span class="n">p</span><span class="p">));</span> <span class="c1">//修改的地方
</span><span class="c1"></span>    <span class="k">return</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">test_fun</span><span class="p">(</span><span class="n">test</span><span class="p">());</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h2 id="任何模板库都离不开完美转发">任何模板库都离不开完美转发</h2>
<p>其实现在只要是C++的模板库，没有哪个是不用完美转发的，同时完美转发的问题也是产生自模板，而 <code>forward</code> 函数的实现其实也不是什么难事，实际就是利用 C++11 对模板提供的万能折叠语义：</p>
<ul>
<li>当实参为左值或者左值引用（A&amp;）时，函数模板中 T&amp;&amp; 将转变为 A&amp;（A&amp; &amp;&amp; = A&amp;）；</li>
<li>当实参为右值或者右值引用（A&amp;&amp;）时，函数模板中 T&amp;&amp; 将转变为 A&amp;&amp;（A&amp;&amp; &amp;&amp; = A&amp;&amp;）。</li>
</ul>
<blockquote>
<p>以下为一个简单的利用完美转发设计的创建工厂：</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span><span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;memory&gt;</span><span class="cp">
</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">test</span><span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">test</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
    <span class="n">test</span><span class="p">(</span><span class="kt">int</span><span class="o">&amp;&amp;</span> <span class="n">arg</span><span class="p">)</span><span class="o">:</span><span class="n">m_iData</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;move construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">test</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span><span class="o">&amp;</span> <span class="n">arg</span><span class="p">)</span><span class="o">:</span><span class="n">m_iData</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;copy construct call&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
    <span class="kt">int</span> <span class="n">m_iData</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="p">,</span><span class="k">typename</span> <span class="n">Arg</span><span class="o">&gt;</span>
<span class="c1">//不直接用T&amp;&amp;的原因在于，如果只使用一个模板参数会导致factory参数无法获得万能引用的效果
</span><span class="c1"></span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">factory</span><span class="p">(</span><span class="n">Arg</span><span class="o">&amp;&amp;</span> <span class="n">arg</span><span class="p">){</span>
    <span class="k">return</span> <span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="k">new</span> <span class="n">T</span><span class="p">(</span><span class="n">forward</span><span class="o">&lt;</span><span class="n">Arg</span><span class="o">&gt;</span><span class="p">(</span><span class="n">arg</span><span class="p">)));</span><span class="c1">//使用完美转发调用正确的构造函数
</span><span class="c1"></span><span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">val</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
    <span class="k">auto</span> <span class="n">p1</span> <span class="o">=</span> <span class="n">factory</span><span class="o">&lt;</span><span class="n">test</span><span class="o">&gt;</span><span class="p">(</span><span class="n">val</span><span class="p">);</span>
    <span class="k">auto</span> <span class="n">p2</span> <span class="o">=</span> <span class="n">factory</span><span class="o">&lt;</span><span class="n">test</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h2 id="stdforward的实现原理">std::forward的实现原理</h2>
<p>gcc 的源代码实现如下：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">_Tp</span><span class="o">&gt;</span>
<span class="k">constexpr</span> <span class="n">_Tp</span> <span class="o">&amp;&amp;</span>
<span class="n">forward</span><span class="p">(</span><span class="k">typename</span> <span class="n">std</span><span class="o">::</span><span class="n">remove_reference</span><span class="o">&lt;</span><span class="n">_Tp</span><span class="o">&gt;::</span><span class="n">type</span> <span class="o">&amp;</span><span class="n">__t</span><span class="p">)</span> <span class="k">noexcept</span> <span class="p">{</span> <span class="k">return</span> <span class="k">static_cast</span><span class="o">&lt;</span><span class="n">_Tp</span> <span class="o">&amp;&amp;&gt;</span><span class="p">(</span><span class="n">__t</span><span class="p">);</span> <span class="p">}</span>

<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">_Tp</span><span class="o">&gt;</span>
<span class="k">constexpr</span> <span class="n">_Tp</span> <span class="o">&amp;&amp;</span>
<span class="n">forward</span><span class="p">(</span><span class="k">typename</span> <span class="n">std</span><span class="o">::</span><span class="n">remove_reference</span><span class="o">&lt;</span><span class="n">_Tp</span><span class="o">&gt;::</span><span class="n">type</span> <span class="o">&amp;&amp;</span><span class="n">__t</span><span class="p">)</span> <span class="k">noexcept</span> <span class="p">{</span>
    <span class="k">static_assert</span><span class="p">(</span><span class="o">!</span><span class="n">std</span><span class="o">::</span><span class="n">is_lvalue_reference</span><span class="o">&lt;</span><span class="n">_Tp</span><span class="o">&gt;::</span><span class="n">value</span><span class="p">,</span> <span class="s">&#34;template argument&#34;</span>
                                                         <span class="s">&#34; substituting _Tp is an lvalue reference type&#34;</span><span class="p">);</span>
    <span class="k">return</span> <span class="k">static_cast</span><span class="o">&lt;</span><span class="n">_Tp</span> <span class="o">&amp;&amp;&gt;</span><span class="p">(</span><span class="n">__t</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div><p>我们发现，源代码中实现了两个模板特化，<code>_Tp&amp;</code> 和 <code>_Tp&amp;&amp;</code> 但最终都是通过 static_cast + 折叠引用的特性来实现强制转化的。也就是简单的强转而已！</p>
<h2 id="收获">收获</h2>
<p>在设计模板库的时候，如果需要根据左值右值语义比较清晰的实现转发，一定要用forward，否则参数只会被当作左值！</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/">C&#43;&#43;右值语义的基石——完美转发</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-02-04</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发" data-hashtags="C&#43;&#43;右值语义的基石——完美转发"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-hashtag="C&#43;&#43;右值语义的基石——完美转发"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发" data-image="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发" data-description="C&#43;&#43;右值语义的基石——完美转发"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发" data-description="C&#43;&#43;右值语义的基石——完美转发"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%8F%B3%E5%80%BC%E8%AF%AD%E4%B9%89%E7%9A%84%E5%9F%BA%E7%9F%B3%E5%AE%8C%E7%BE%8E%E8%BD%AC%E5%8F%91/" data-title="C&#43;&#43;右值语义的基石——完美转发"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98%E5%92%8C%E4%B8%BAk%E7%9A%84%E6%9C%80%E5%B0%91%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%AD%97%E6%95%B0%E7%9B%AE/" class="prev" rel="prev" title="leetcode每日一题——和为K的最少斐波那契数字数目"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/c&#43;&#43;%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%AE%9E%E7%8E%B0%E5%AD%A6%E7%94%9F%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/" class="next" rel="next" title="C&#43;&#43;图形化实现学生管理系统">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
